package chapters.c1
{
	import flash.utils.Dictionary;
	
	import global.$R;
	import global.$talkScene;
	
	import slices.BlankTime;
	import slices.TimeSlice;
	import globals.$athena;
	import loaders.LoadManager;
	
	import resources.LoadResource;
	import resources.RTBackground;
	import resources.RTProfile;
	
	import slices.FunctionSlice;
	import timeslice.LoadURLResource;
	import slices.SwitchToScene;
	import timeslice.TalkSceneAddChar;
	import timeslice.TalkSceneTalk;
	import timeslice.TimeLine;
	
	public class TL1_1 extends TimeLine
	{
		public var load:LoadResource;
		
		public var current:TimeSlice;
		public var heads:Array;

		public function TL1_1()
		{
			super();
		}
		
		override public function onStart():void {
			var loader:LoadResource = new LoadResource;
			loader.add(new RTProfile(RTProfile.A));
			loader.add(new RTProfile(RTProfile.B));
			loader.add(new RTBackground(RTBackground.BG_0));
			var func:FunctionSlice = new FunctionSlice(onResourceLoad);
			loader.appendNext(func);
			$athena.addTimeSlice(load);						
		}
		
		private function onResourceLoad():void {
			$talkScene.setBackGround($R.getBackground(RTBackground.BG_0));
			appendSlice(new SwitchToScene($talkScene));
			appendSlice(new TalkSceneAddChar(RTProfile.A, 0, 0, false));
			appendSlice(new TalkSceneAddChar(RTProfile.B, 3));
			appendSlice(new BlankTime(500));
			appendSlice(new TalkSceneTalk(RTProfile.A, "亲爱的，你真的想好了吗？"));
			appendSlice(new TalkSceneTalk(RTProfile.A, "永葆青春的副作用现在还没有被发现呢", 2));
			appendSlice(new TalkSceneTalk(RTProfile.B, "嗯，没发现就是没有，相信科学的发展吧"));
			appendSlice(new TalkSceneTalk(RTProfile.B, "我想和你在一起永远没有衰老，没有疾病，快乐的生活", 3));
			appendSlice(new TalkSceneTalk(RTProfile.A, "好...那我们向研究中心出发吧", 0));
			begin();
		}
		
		private function appendSlice(...tss):void {
			var ts:TimeSlice;
			if (current == null) {
				heads = tss;
			} else {
				for each (ts in tss) {
					current.appendNext(ts);
				}
			}
			if (tss.length > 0)	{
				current = tss[0];
			}
		}
		
		private function begin():void {
			for each (var ts:TimeSlice in heads) {
				$athena.addTimeSlice(ts);
			}
		}
	}
}